package in.muton.edushare.pages.publicpages.userpages;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.pages.user.UserCourses;
import in.muton.edushare.pages.user.UserDept;
import in.muton.edushare.pages.user.UserPage;
import in.muton.edushare.pages.user.UserUniv;

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;

public class HeaderPanel extends Panel {

	private static final long serialVersionUID = 4933519634416555825L;

	public HeaderPanel(String id) {
		super(id);
		if(EduShareSession.get().isLoggedIn()){
			add(new LoggedInMenuFrag("menuDiv", this));
		}else{
			add(new NotLoggedInMenuFrag("menuDiv", this));
		}
	}
	
	public class LoggedInMenuFrag extends Fragment{

		private static final long serialVersionUID = -4595462784202700158L;

		public LoggedInMenuFrag(String id, MarkupContainer container) {
			super(id, "loggedInMenuFrag", container);
			add(new BookmarkablePageLink<Void>("home", UserPage.class));
			add(new BookmarkablePageLink<Void>("calendar", UserPage.class));
			add(new BookmarkablePageLink<Void>("univs", UserUniv.class));
			add(new BookmarkablePageLink<Void>("depts", UserDept.class));
			add(new BookmarkablePageLink<Void>("courses", UserCourses.class));
			add(new BookmarkablePageLink<Void>("settings", UserPage.class));
			add(new Link<String>("logout") {
		
						private static final long serialVersionUID = 9157171216727269598L;

						@Override
						public void onClick() {
							EduShareSession.get().logOutUser();
							getSession().invalidate();
							setResponsePage(in.muton.edushare.pages.EduShareLogin.class);
						}
					});
		}
		
	}
	
	public class NotLoggedInMenuFrag extends Fragment{

		private static final long serialVersionUID = 3785488358671073694L;

		public NotLoggedInMenuFrag(String id, MarkupContainer container) {
			super(id, "notLoggedInMenuFrag", container);
			add(new Link<String>("loginLink") {
				
				private static final long serialVersionUID = -9073794045085884534L;

				@Override
				public void onClick() {
					setResponsePage(in.muton.edushare.pages.EduShareLogin.class);
				}
			});
		}
		
	}

}